#include "./JParserNamespace.h"
#include "./JParser.h"
#include "./JNode.h"
//#include <MyTextFileReaderAndWriterInterface.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <chrono>
#include <functional>
//#pragma(lib,"MyTextFileReaderAndWriterDLL.lib");

void testRunTime(const std::string& msg, const std::function<void()>& func)
{
	long long times = 1000000;
	long long total_time = 0;
	for (int i = 0; i < times; i++)
	{
		auto start = std::chrono::high_resolution_clock::now();
		func();
		auto end = std::chrono::high_resolution_clock::now();
		auto duration_time = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
		total_time += duration_time;
	}
	std::cout << "\033[32m" << "info: " << "\033[0m" << msg << std::endl;
	std::cout << "\033[32m" << "time: " << "\033[0m" << static_cast<double>(total_time) / static_cast<double>(times) / 1000.0l << "ms" << std::endl;
	std::cout << std::endl;
}

void testMain()
{
	testRunTime("string构造", []()
		{
			myjson::JSONParser j("{\"null\":null,\"true\":true,\"double\":6174.617400,\"false\":false,\"int\":6174,\"object\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174,\"vector_obj\":[null,true,false,6174,6174.617188],\"obj_obj\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}},\"vector\":[null,true,false,6174,6174.617400,[null,true,false,6174,6174.617188],{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}]}");
			j;
		});
	testRunTime("解析", []()
		{
			myjson::JSONParser j("{\"null\":null,\"true\":true,\"double\":6174.617400,\"false\":false,\"int\":6174,\"object\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174,\"vector_obj\":[null,true,false,6174,6174.617188],\"obj_obj\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}},\"vector\":[null,true,false,6174,6174.617400,[null,true,false,6174,6174.617188],{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}]}");
			j.parse();
		});
}

int main()
{
	testMain();
	while (1);
	return 0;
}

//{"null":null,"true":true,"double":6174.617400,"false":false,"int":6174,"object":{"null_obj":null,"true_obj":true,"false_obj":false,"double_obj":6174.617188,"int_obj":6174,"vector_obj":[null,true,false,6174,6174.617188],"obj_obj":{"null_obj":null,"true_obj":true,"false_obj":false,"double_obj":6174.617188,"int_obj":6174}},"vector":[null,true,false,6174,6174.617400,[null,true,false,6174,6174.617188],{"null_obj":null,"true_obj":true,"false_obj":false,"double_obj":6174.617188,"int_obj":6174}]}
//"{\"null\":null,\"true\":true,\"double\":6174.617400,\"false\":false,\"int\":6174,\"object\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174,\"vector_obj\":[null,true,false,6174,6174.617188],\"obj_obj\":{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}},\"vector\":[null,true,false,6174,6174.617400,[null,true,false,6174,6174.617188],{\"null_obj\":null,\"true_obj\":true,\"false_obj\":false,\"double_obj\":6174.617188,\"int_obj\":6174}]}"
